package com.sky.config;
//操作步骤：
//1:导入Spring Data Redis 的maven坐标
//2:配置Redis数据源
//3:编写配置类，创建RedisTemplate对象
//4:通过RedisTemplate对象操作Redis

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@Slf4j
public class RedisConfiguration {
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        log.info("开始创建redis模版对象...");
        RedisTemplate redisTemplate = new RedisTemplate();
        //设置redis的连接工厂对象(手动创建的目的)
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        //设置redis key 的序列器
        redisTemplate.setKeySerializer(new StringRedisSerializer());//把key变成字符串类型，不会乱码
        return redisTemplate;
    }
}
